import 'package:dmz/base/controller/base_controller.dart';
import 'package:dmz/business/home/controller/set_infor_controller.dart';
import 'package:dmz/business/home/model/moto_record.dart';
import 'package:dmz/business/home/model/ota_record_model.dart';
import 'package:dmz/utils/Utils.dart';
import 'package:get/get.dart';

import '../../../request/apis.dart';
import '../../../request/request_client.dart';

class OtaRecordController extends BaseController {
  String? snCode;
  List<MotoRecord> list = [];
  String? title;
  bool showNoData = false;
  @override
  void loadNet() {
    // TODO: implement loadNet
  }

  @override
  void onHidden() {
    // TODO: implement onHidden
  }

  @override
  void onInit() {
    super.onInit();
    var motoInfoController = Get.find<SetMotoInforController>();
    snCode = motoInfoController.data!.sn_code;
    if (Utils.isNotEmptyString(motoInfoController.data!.name)) {
      title = '${motoInfoController.data!.name}升级记录';
    }
    otaRecord(1);
  }

  otaRecord(index) {
    RequestClient().post<OtaRecordModel>(APIS.record,
        data: {'sn_code': snCode, 'index': index, 'size': 50}).then((value) {
      if (value != null) {
        if (Utils.isNotEmptyList(list)) {
          list.clear();
        }
        list.addAll(value.list!);
        if (Utils.isNotEmptyList(list)) {
          showNoData = false;
        } else {
          showNoData = true;
        }
        update();
      }
    });
  }
}

class SetOtaRecordBinding extends Bindings {
  @override
  void dependencies() {
    Get.lazyPut(() => OtaRecordController(), fenix: true);
  }
}
